package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * 我的余额变化
 * fx
 */
public class MyYueBianHuaTask extends CouponHttpBaseTask {
    private int mSize;
    private int mPageNo;

    private static final String SELLERLIST = "balanceList";

    public MyYueBianHuaTask(int size, int pageNo) {
        super(TaskType.MYYUEBIANHUA_TASK);
        mSize = size;
        mPageNo = pageNo;

    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        JSONObject jsonString = null;
        if (respJson != null) {
            jsonString = respJson.getJSONObject(SELLERLIST);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, jsonString);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.MYYUEBIANHUA_REQUEST);
            JSONObject json = new JSONObject();
            json.put("size", mSize);
            json.put("pageNo", mPageNo);
            request.setData(json.toString());
            request.setApiNo(ApiNo.MYYUEBIANHUA);
            addRequest(request);
        }
    }
}
